package com.chongqing.shiro.service.impl;


import com.chongqing.shiro.mapper.PermissionMapper;
import com.chongqing.shiro.model.entity.Permission;
import com.chongqing.shiro.service.PermissionService;
import com.chongqing.shiro.util.CoreConst;
import com.chongqing.shiro.util.UUIDUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Set;

/**
 * @Description: 权限实现类
 * -------------------
 * @Author: YangXingfu
 * @Date: 2019/01/04 17:53
 */

@Service
public class PermissionServiceImpl implements PermissionService {

    @Autowired
    private PermissionMapper permissionMapper;

    @Override
    public List<Permission> selectAll(Integer status) {
        List<Permission> permissions = null;
        permissions = permissionMapper.selectPermissions(status);
        return permissions;
    }

    @Override
    public List<Permission> selectMenusByUserId(String userId) {
        return permissionMapper.selectMenusByUserId(userId);
    }

    @Override
    public Set<String> findPermsByUserId(String userId) {
        return permissionMapper.findPermsByUserId(userId);
    }

    @Override
    public List<Permission> selectAllMenuName(Integer statusValid) {
        return permissionMapper.selectAllMenuName(statusValid);
    }

    @Override
    public int insert(Permission permission) {
        Date date = new Date();
        permission.setPermissionId(UUIDUtil.getHashUUID());
        permission.setStatus(CoreConst.STATUS_VALID);
        permission.setCreateTime(date);
        permission.setUpdateTime(date);
        return permissionMapper.insert(permission);
    }

    @Override
    public Permission findByPermissionId(String permissionId) {
        return permissionMapper.findByPermissionId(permissionId);
    }

    @Override
    public Permission findById(Integer parentId) {
        return permissionMapper.selectByPrimaryKey(parentId);
    }

    @Override
    public int updateByPermissionId(Permission permission) {
        return permissionMapper.updateByPermissionId(permission);
    }

    @Override
    public int selectSubPermsByPermissionId(String permissionId) {
        return permissionMapper.selectSubPermsByPermissionId(permissionId);
    }

    @Override
    public int updateStatus(String permissionId, Integer status) {
        return permissionMapper.updateStatus(permissionId, status);
    }
}